package com.health.demo.common.vo;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    //    状态码（200：成功，500：失败）
    private Integer code;
    //    提示信息
    private String msg;
    //    数据
    private T data;


    public Result(Integer code) {
        this.code = code;
    }

    public Result(Integer code, T data) {
        this.code = code;
        this.data = data;
    }

    public enum ResultStatus {

        SUCCESS(200), ERROR(500);

        public Integer code;

        private ResultStatus(Integer code) {
            this.code = code;
        }
    }
    //01
    public static <T> Result<T> ok() {
        return new Result<T>(Result.ResultStatus.SUCCESS.code, "Success.", null);
    }
    //02
    public static <T> Result<T> ok(String msg) {
        return new Result<T>(Result.ResultStatus.SUCCESS.code, msg, null);
    }

    //03
    public static <T> Result<T> ok(T data) {
        return new Result<T>(Result.ResultStatus.SUCCESS.code, "Success.", data);
    }
    //04
    public static <T> Result<T> ok(String msg,T data) {
        return new Result<T>(Result.ResultStatus.SUCCESS.code, msg, data);
    }

    //01
    public static <T> Result<T> error() {
        return new Result<T>(Result.ResultStatus.ERROR.code, "error.", null);
    }
    //02
    public static <T> Result<T> error(String msg) {
        return new Result<T>(Result.ResultStatus.ERROR.code, msg, null);
    }
    //03
    public static <T> Result<T> error(T data) {
        return new Result<T>(Result.ResultStatus.ERROR.code, "error.", data);
    }
    //04
    public static <T> Result<T> error(String msg,T data) {
        return new Result<T>(Result.ResultStatus.ERROR.code, msg, data);
    }
}
